<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/common.jsp"%>
<!DOCTYPE html>
<html lang="zh">
<meta charset="utf-8">
<head></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-news-add">
			<div class="form-group">
				<label class="col-sm-2 control-label">新闻标题：</label>
				<div class="col-sm-10">
					<input id="newsTitle" name="newsTitle" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">新闻内容：</label>
				<div class="col-sm-10">
					<%--<input id="summernotenewsContent" name="newsContent" class="form-control" type="text">--%>
					<div id="newsContent"></div>

				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">新闻缩放图：</label>
				<div class="col-sm-5">
					<!--id是给jquery使用的，name是给后台action使用的，必须和后台的名字相同！！ -->
					<input type="file" id="addUpload" name="upload" onchange="uploadFile()" class="form-control"
						accept="image/*" />
					<input type="hidden" id="newsPhotoUrl" name="newsPhotoUrl"/>
				</div>
				<div class="col-sm-5">
					<img class="img-rounded" width="100" height="100" id="img"
						src="${ctx }/${empty picture.pictureCPZ ?'img/de.png':picture.pictureCPZ}" class="img-thumbnail" />
				</div>

			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">是否置顶：</label>
				<div class="col-sm-10">
					<div class="onoffswitch">
						<input id="newsTop" name="newsTop" class="onoffswitch-checkbox" type="checkbox">
						<label class="onoffswitch-label" for="newsTop">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">类型：</label>
				<div class="col-sm-10">
					<div class="onoffswitch">
						<select id="newsType" name="newsType"  >
							<option value="0">新闻发布</option>
							<option value="1">税务政策</option>
						</select>.

					</div>
				</div>
			</div>



		</form>
	</div>
	<script src="${ctx}/static/js/wangEditor.min.js"></script>
	<script type="text/javascript">
	
	
		var E = window.wangEditor
		var editor = new E('#newsContent')
		editor.create();
		editor.$textElem.attr('summernotenewsContent', false)
	
		var prefix = "${ctx}/system/news"
		$("#form-news-add").validate({
			rules : {
				newsTitle : {
					required : true,
					minlength : 2,
					maxlength : 30,
				},
			}
		});
	
		function submitHandler() {
			if ($.validate.form()) {
				if (editor.txt.text() == "") {
					alert("请填写新闻内容!");
					return;
				} else if (editor.txt.text().length > 6000) {
					alert("新闻内容过长!");
					return;
				}
	
				$.post(prefix + "/add",
					{
						newsTitle : $.trim($("#newsTitle").val()),
						newsContent : editor.txt.html(),
						newsTop : $("input[name='newsTop']").is(':checked') == true ? 0 : 1,
                        newsPhotoUrl:$("#newsPhotoUrl").val()
					}, function(data,) {
						$.operate.successCallback(data);
					});
			}
		}
	
	
		function uploadFile() {
			var formData = new FormData();
			formData.append("upload", $("#addUpload")[0].files[0]); //第一个file1代表后台文件属性名，第二个file1表示html中input的id
			$.ajax({
				type : "post",
				url : "${ctx}/file/upload.action",
				data : formData,
				processData : false,
				contentType : false,
				dataType : 'json',
				success : function(data) {
					if (data.code == 0) {
                        $("#newsPhotoUrl").val(data.data.path);
						$("#img").attr("src", "${ctx }/" + data.data.path);
					}
				},
				error : function(msg) {
					alert(msg.responsText);
				}
			});
		}
	</script>
</body>
</html>
